//
//  SetUpViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/15.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "SetUpViewController.h"
#import "ForGoPasswordViewController.h"

static NSString *cellPath = @"SetUpCell";
@interface SetUpViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *titAry;
@property (nonatomic, strong)NSArray *imgAry;

@end

@implementation SetUpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _titAry = @[@"修改密码",@"退出登录"];
    _imgAry = @[@"my_icon16",@"my_icon17"];
    [self creatUI];
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = BacksColor;
    self.navigationItem.title = @"设置";
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SCREER_HeiX-STA_NAV_HEIGHT) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = BacksColor;
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 10*displaywidth, SCREEN_WIDTH, 45*displaywidth)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [cell.contentView addSubview:whiteView];
    UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:_imgAry[indexPath.row]];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    [whiteView addSubview:imgView];
    UILabel *namelab = [ZCControl createLabelWithFrame:CGRectMake(45*displaywidth, 5*displaywidth, 120*displaywidth, 35*displaywidth) Font:14.0 Text:_titAry[indexPath.row] Color:BlaTitColor];
    [whiteView addSubview:namelab];

    return cell;
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        ForGoPasswordViewController *Vc = [[ForGoPasswordViewController alloc] init];
        Vc.titleString = @"修改密码";
        [self.navigationController pushViewController:Vc animated:YES];
    }
    else
    {
        [self requestUserLogout];
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55*displaywidth;
}



- (void)requestUserLogout
{
    WEAKSELF;
    [HYBaseHandler requestWithTheFormUrl:SERVER_userLogout Parmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            [LTools storage:NO ForKey:SERVER_IsLogin];
            [LTools cache:@"" ForKey:SERVER_LoginToken];
            [LTools showMBProgressWithText:@"退出成功" addToView:sharedDelegate.window];
            sharedDelegate.tabbarViewController.selectedIndex = 0;
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            
        }

    } failed:^(NSError *error) {
        
    }];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
